﻿using System;
using System.Data;
using System.Collections.Generic;
namespace NS.BLL
{
	/// <summary>
	/// Shops
	/// </summary>
	public partial class Shops
	{
		private readonly NS.DAL.Shops dal=new NS.DAL.Shops();
		public Shops()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int ShopID)
		{
			return dal.Exists(ShopID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(NS.Model.Shops model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(NS.Model.Shops model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int ShopID)
		{
			
			return dal.Delete(ShopID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string ShopIDlist )
		{
			return dal.DeleteList(ShopIDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public NS.Model.Shops GetModel(int ShopID)
		{
			
			return dal.GetModel(ShopID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public NS.Model.Shops GetModelByCache(int ShopID)
		{
			
			string CacheKey = "ShopsModel-" + ShopID;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(ShopID);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (NS.Model.Shops)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<NS.Model.Shops> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<NS.Model.Shops> DataTableToList(DataTable dt)
		{
			List<NS.Model.Shops> modelList = new List<NS.Model.Shops>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				NS.Model.Shops model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new NS.Model.Shops();
					if(dt.Rows[n]["ShopID"]!=null && dt.Rows[n]["ShopID"].ToString()!="")
					{
						model.ShopID=int.Parse(dt.Rows[n]["ShopID"].ToString());
					}
					if(dt.Rows[n]["ShopName"]!=null && dt.Rows[n]["ShopName"].ToString()!="")
					{
					model.ShopName=dt.Rows[n]["ShopName"].ToString();
					}
					if(dt.Rows[n]["ShopSlogan"]!=null && dt.Rows[n]["ShopSlogan"].ToString()!="")
					{
					model.ShopSlogan=dt.Rows[n]["ShopSlogan"].ToString();
					}
					if(dt.Rows[n]["ShopIntro"]!=null && dt.Rows[n]["ShopIntro"].ToString()!="")
					{
					model.ShopIntro=dt.Rows[n]["ShopIntro"].ToString();
					}
					if(dt.Rows[n]["ShopNotice"]!=null && dt.Rows[n]["ShopNotice"].ToString()!="")
					{
					model.ShopNotice=dt.Rows[n]["ShopNotice"].ToString();
					}
					if(dt.Rows[n]["ShopAccount"]!=null && dt.Rows[n]["ShopAccount"].ToString()!="")
					{
					model.ShopAccount=dt.Rows[n]["ShopAccount"].ToString();
					}
					if(dt.Rows[n]["Password"]!=null && dt.Rows[n]["Password"].ToString()!="")
					{
					model.Password=dt.Rows[n]["Password"].ToString();
					}
					if(dt.Rows[n]["QQ"]!=null && dt.Rows[n]["QQ"].ToString()!="")
					{
					model.QQ=dt.Rows[n]["QQ"].ToString();
					}
					if(dt.Rows[n]["Age"]!=null && dt.Rows[n]["Age"].ToString()!="")
					{
						model.Age=int.Parse(dt.Rows[n]["Age"].ToString());
					}
					if(dt.Rows[n]["Location"]!=null && dt.Rows[n]["Location"].ToString()!="")
					{
					model.Location=dt.Rows[n]["Location"].ToString();
					}
					if(dt.Rows[n]["Height"]!=null && dt.Rows[n]["Height"].ToString()!="")
					{
						model.Height=int.Parse(dt.Rows[n]["Height"].ToString());
					}
					if(dt.Rows[n]["Weight"]!=null && dt.Rows[n]["Weight"].ToString()!="")
					{
						model.Weight=int.Parse(dt.Rows[n]["Weight"].ToString());
					}
					if(dt.Rows[n]["Job"]!=null && dt.Rows[n]["Job"].ToString()!="")
					{
					model.Job=dt.Rows[n]["Job"].ToString();
					}
					if(dt.Rows[n]["OnlineTime"]!=null && dt.Rows[n]["OnlineTime"].ToString()!="")
					{
					model.OnlineTime=dt.Rows[n]["OnlineTime"].ToString();
					}
					if(dt.Rows[n]["AddTime"]!=null && dt.Rows[n]["AddTime"].ToString()!="")
					{
						model.AddTime=DateTime.Parse(dt.Rows[n]["AddTime"].ToString());
					}
					if(dt.Rows[n]["LastUpdateTime"]!=null && dt.Rows[n]["LastUpdateTime"].ToString()!="")
					{
						model.LastUpdateTime=DateTime.Parse(dt.Rows[n]["LastUpdateTime"].ToString());
					}
					if(dt.Rows[n]["IsAvailable"]!=null && dt.Rows[n]["IsAvailable"].ToString()!="")
					{
						model.IsAvailable=int.Parse(dt.Rows[n]["IsAvailable"].ToString());
					}
					if(dt.Rows[n]["IsDeleted"]!=null && dt.Rows[n]["IsDeleted"].ToString()!="")
					{
						model.IsDeleted=int.Parse(dt.Rows[n]["IsDeleted"].ToString());
					}
					if(dt.Rows[n]["DeletedTime"]!=null && dt.Rows[n]["DeletedTime"].ToString()!="")
					{
						model.DeletedTime=DateTime.Parse(dt.Rows[n]["DeletedTime"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

